<style>
    .operator-mg{
        background:#FFFEE6;
        color:#8F5700;
        padding:12px;
    }
    .operator-mg-tip{
        width:16px;
        height:16px;
        margin-right:8px;
        float:left;
    }
    #search{

    }
</style>
<script type="text/javascript">
    function serviceChatReset() {
        $('#service-chat-account').val('');
        $('#service-chat-name').val('');
        $('#service-chat-stime').datetimebox('setValue', '');
        $('#service-chat-etime').datetimebox('setValue', '');
    }
    function serviceChatSearch() {
        $('#service-chat-list').datagrid('load', {
            account: $('#service-chat-account').val(),
            name: $('#service-chat-name').val(),
            stime: $('#service-chat-stime').datetimebox('getValue'),
            etime: $('#service-chat-etime').datetimebox('getValue')
        });
    }
    //添加右击菜单内容
    function onRowMenuServiceChat(e, rowIndex, rowData) {
        e.preventDefault();
        var selected = $("#service-chat-list").datagrid('getRows'); //获取所有行集合对象
        selected[rowIndex].id; //index为当前右键行的索引，指向当前行对象
        $('#service-chat-dlg_menu').menu('show', {
            left: e.pageX,
            top: e.pageY
        });
    }
    function serviceChatSaveFileDialog() {
        if ($("#service-chat-list").datagrid('getSelected')) {
            $('#service-chat-dlg').dialog('open').dialog('setTitle', '下载记录');
        } else {
            $.messager.confirm('错误', '请左击选中条目');
        }
    }
    function serviceChatDownload(isRow) {
        var downloadForm = document.forms['service-chat-download'];
        if (isRow) {
            var record = '';
            var rows = $("#service-chat-list").datagrid('getSelections');
            for (var i = 0; i < rows.length; i++) {
                record = record + rows[i].time + "  客服：" + rows[i].service_account + "  会话:" + rows[i].sid + "  客户ip：" + rows[i].ip + "  客户临时id:" + rows[i].cid + "  咨询记录：" + rows[i].content + "\\r\\n";
            }
            $('#service-chat-download-record').val(record);
            downloadForm.action = "<?php echo $this->config->item('base_url'); ?>service/downloadwithdata";
            downloadForm.submit();
        } else {
            $('#service-chat-download-account').val($('#service-chat-account').val());
            $('#service-chat-download-name').val($('#service-chat-name').val());
            $('#service-chat-download-stime').val($('#service-chat-stime').datetimebox('getValue'));
            $('#service-chat-download-etime').val($('#service-chat-etime').datetimebox('getValue'));
            downloadForm.action = "<?php echo $this->config->item('base_url'); ?>service/download";
            downloadForm.submit();
        }
        $('#service-chat-dlg').dialog('close');
    }
</script>
<div class="operator-mg">
    <div class="operator-mg-tip icon-tip"></div>
    <div>温馨提示：在列表中点击右键可以弹出操作菜单</div>
</div>
<!--数据表格-->
<table id="service-chat-list" class="easyui-datagrid"  title="解答记录" toolbar="#service-chat-tb"
       url="<?php echo $this->config->item('base_url'); ?>service/getchatlog"
       rownumbers="true" pagination="true" fitColumns="true"
       data-options ="onRowContextMenu:onRowMenuServiceChat"
       >
    <thead>
        <tr>
            <th checkbox="true"></th>
            <th field="id" align="center" width="40">ID</th>
            <th field="sid" align="center" width="40">会话</th>
            <th field="service_account" align="center" width="50">客服账户</th>
            <th field="content" align="center" width="160">聊天内容</th>
            <th field="time" align="center" width="55">聊天时间</th>
<!--            <th field="filepath" align="center" width="50">上传文件路径</th>-->
            <th field="ip" align="center" width="80">来源IP</th>
            <th field="cid" align="center" width="50">web客户临时id</th>
        </tr>
    </thead>
</table>
<!--工具栏及搜索框-->
<div id="service-chat-tb" style="padding:10px;height:auto">
    <div style="padding:10px;">
        客服账号：<input id="service-chat-account" style="width:80px">
        客服姓名：<input id="service-chat-name" style="width:80px">
        指定时间段：
        从<input id="service-chat-stime" class="easyui-datetimebox"  style="width:150px">
        到<input id="service-chat-etime" class="easyui-datetimebox" style="width:150px">
        <br/><br/>
        <button onclick="serviceChatSearch()">搜索</button>
        <button onclick="serviceChatDownload()">下载</button>
        <button onclick="serviceChatReset()">重置</button>
    </div>
    <form method="post" id="service-chat-download" hidden="true">
        <input id="service-chat-download-record" name="record">
        <input id="service-chat-download-account" name="account">
        <input id="service-chat-download-name" name="name">
        <input id="service-chat-download-stime" name="stime">
        <input id="service-chat-download-etime" name="etime">
    </form>
</div>
<!--右键菜单-->
<div id="service-chat-dlg_menu" class="easyui-menu" style="width:120px;">
    <div onClick="serviceChatSaveFileDialog()" data-options="iconCls:'icon-save'">下载</div>
    <div class="menu-sep"></div>
    <div onClick="$('#service-chat-list').datagrid('reload');" data-options="iconCls:'icon-reload'">刷新</div>
</div>
<!--本地保存弹窗-->
<div id="service-chat-dlg" class="easyui-dialog" style="width:auto;height:auto;padding:10px 20px"
     closed="true" buttons="#service-chat-dlg-buttons">
    <span>您将下载所有被选中的记录</span>
</div>
<div id="service-chat-dlg-buttons">
    <a class="easyui-linkbutton" iconCls="icon-ok" onclick="serviceChatDownload('rows')">下载</a>
    <a class="easyui-linkbutton" iconCls="icon-cancel" onclick="$('#service-chat-dlg').dialog('close')">取消</a>
</div>
